#!/bin/sh 
# 
# script to bring up the tun device in QEMU in bridged mode 
# first parameter is name of tap device (e.g. tap0)
#
# some constants specific to the local host - change to suit your host
#
ETH0IPADDR=192.168.1.197
MASK=255.255.255.0
GATEWAY=192.168.1.197
BROADCAST=192.168.1.255
#
# First take eth0 down, then bring it up with IP address 0.0.0.0 
#
ifdown enp3s0
ifconfig enp3s0 0.0.0.0 promisc up
#
# Bring up the tap device (name specified as first argument, by QEMU)
#
openvpn --mktun --dev $1 --user `id -un`
ifconfig $1 0.0.0.0 promisc up
#
# create the bridge between eth0 and the tap device
#
brctl addbr br0
brctl addif br0 enp3s0
brctl addif br0 $1
# 
# only a single bridge so loops are not possible, turn off spanning tree protocol
#
brctl stp br0 off 
# 
# Bring up the bridge with ETH0IPADDR and add the default route 
#
ifconfig br0 $ETH0IPADDR netmask $MASK broadcast $BROADCAST
route add default gw $GATEWAY
